class HttpException extends Error {
  constructor(msg = '服务器异常', errcode = 10000, code = 400) {
    super()
    this.errcode = errcode
    this.code = code
    this.msg = msg
  }
}

class ParameterException extends HttpException {
  constructor(msg, errcode) {
    super()
    this.code = 400
    this.msg = msg || '参数错误'
    this.errcode = errcode || 10000
  }
}

class AuthFailed extends HttpException {
  constructor(msg, errcode) {
    super()
    this.code = 401
    this.msg = msg || '授权失败'
    this.errcode = errcode || 10004
  }
}

class NotFound extends HttpException {
  constructor(msg, errcode) {
    super()
    this.code = 404
    this.msg = msg || '404找不到'
    this.errcode = errcode || 10005
  }
}

class Forbidden extends HttpException {
  constructor(msg, errcode) {
    super()
    this.code = 200
    this.msg = msg || '禁止访问'
    this.errcode = errcode || 10006
  }
}

class Existing extends HttpException {
  constructor(msg, errcode) {
    super()
    this.code = 412
    this.msg = msg || '已存在'
    this.errcode = errcode || 10006
  }
}

class NotExist extends HttpException {
    constructor(msg, errcode) {
        super()
        this.code = 413
        this.msg = msg || '不存在'
        this.errcode = errcode || 10008
    }
}

class ServerError extends HttpException {
  constructor(msg, errcode) {
    super()
    this.code = 200
    this.msg = msg || '服务器错误'
    this.errcode = errcode || 50000
}
}

export default {
  HttpException,
  ParameterException,
  AuthFailed,
  NotFound,
  Forbidden,
  Existing,
  NotExist,
  ServerError
}
